package lib.persistence.commands;


import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import lib.Field;

public abstract class CommandAbstract {

	protected void setParameter(List<Field> fields, PreparedStatement statement, int i)
			throws SQLException{
				if (fields.get(i).getType().equalsIgnoreCase("int") || fields.get(i).getType().equalsIgnoreCase("integer")) 
					statement.setInt(i + 1, Integer.parseInt(fields.get(i).getValue()));
				else if (fields.get(i).getType().equalsIgnoreCase("string"))
					statement.setString(i + 1, fields.get(i).getValue());
				else if (fields.get(i).getType().equalsIgnoreCase("date"))
				{
					Date date = (Date) fields.get(i).getObjValue();
					statement.setString(i + 1, (date.getYear()+1900)+"-"+date.getMonth()+"-"+date.getDay());
				}
				else if (fields.get(i).getType().equalsIgnoreCase("object") || fields.get(i).getType().equalsIgnoreCase("blob"))
					statement.setObject(i + 1, fields.get(i).getObjValue());
			}

}
